package com.xbongbong.saas.model.impl;

import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.util.DateTimeUtil;
import com.xbongbong.pro.domain.dao.PersonLabelDao;
import com.xbongbong.pro.domain.entity.PersonLabelEntity;
import com.xbongbong.saas.model.PersonLabelModel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author jiangren.li
 * @Title:
 * @date 2020/11/219:01
 */
@Service("personLabelModel")
public class PersonLabelModelImpl implements PersonLabelModel {
    @Resource
    private PersonLabelDao personLabelDao;

    @Override
    public Integer insert(PersonLabelEntity entity) throws XbbException {
        long now = DateTimeUtil.getInt();
        entity.setAddTime(now);
        entity.setUpdateTime(now);
        return personLabelDao.insert(entity);
    }

    @Override
    public Integer updateLabelName(PersonLabelEntity entity) throws XbbException {
        entity.setUpdateTime(DateTimeUtil.getInt());
        return personLabelDao.updateLabelName(entity);
    }

    @Override
    public PersonLabelEntity getByParamColumns(Map<String, Object> param) {
        return personLabelDao.getByParamColumns(param);
    }

    @Override
    public PersonLabelEntity getPersonLabelByRefType(String corpid, Integer refType, Long refId, String ownerId) {
        Map<String, Object> param = new HashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        param.put("corpid", corpid);
        param.put("refType", refType);
        param.put("refId", refId);
        param.put("ownerId", ownerId);
        return  getByParamColumns(param);
    }
}
